import dayjs from 'dayjs'
import { isUndefined } from './helpers'

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'

/**
 * 格式化时间
 * @param timestamp 时间戳(10位)
 * @returns
 */
export const formatTime = (timestamp: number): string => {
  if (isUndefined(timestamp)) return ''
  timestamp = timestamp * 1000

  return dayjs(timestamp).format(DATE_TIME_FORMAT)
}
